#ifndef __LIBCO_MACRO_H__
#define __LIBCO_MACRO_H__

#include <cassert>
#include "util.h"
#include "log.hpp"


#if defined __GNUC__ || defined __llvm__
/// LIKCLY 宏的封装, 告诉编译器优化,条件大概率成立
#define LIBCO_LIKELY(x) __builtin_expect(!!(x), 1)
/// LIKCLY 宏的封装, 告诉编译器优化,条件大概率不成立
#define LIBCO_UNLIKELY(x) __builtin_expect(!!(x), 0)
#else
#define LIBCO_LIKELY(x) (x)
#define LIBCO_UNLIKELY(x) (x)
#endif

/// 断言宏封装
#define LIBCO_ASSERT(x)                                \
    if (LIBCO_UNLIKELY(!(x)))                          \
    {                                                  \
        LIBCO_LOG_ERROR << "ASSERTION: " #x; assert(x); \
    }

/// 断言宏封装
#define LIBCO_ASSERT2(x, w)                 \
    if (LIBCO_UNLIKELY(!(x)))               \
    {                                       \
        LIBCO_LOG_ERROR << "ASSERTION: " #x \
                        << "\n"             \
                        << (w);                \
                               assert(x);   \
    }

#endif